package com.hddf.project.impl;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.hddf.project.base.BaseDaoImpl;
import com.hddf.project.dao.ThirdCategoryDao;
import com.hddf.project.pojos.ThirdCategory;

public class ThirdCategoryDaoImpl extends BaseDaoImpl implements ThirdCategoryDao {

	/**
	 * 添加三级类别
	 * 
	 * @param tc
	 * @param s
	 */
	public void add(ThirdCategory tc, Session s) throws Exception {
		super.add(tc, s);
	}

	/**
	 * 删除三级类别
	 * 
	 * @param third_category_id
	 * @param s
	 */
	public void delete(int third_category_id, Session s) throws Exception {
		super.deleteById(ThirdCategory.class, third_category_id, s);
	}

	/**
	 * 删除三级类别
	 * 
	 * @param tc
	 * @param s
	 */
	public void delete(ThirdCategory tc, Session s) throws Exception {
		super.delete(tc, s);
	}

	/**
	 * 修改三级类别
	 * 
	 * @param tc
	 * @param s
	 */
	public void update(ThirdCategory tc, Session s) throws Exception {
		super.update(tc, s);
	}

	/**
	 * 获取指定三级类别
	 * 
	 * @param third_category_id
	 * @param s
	 * @return
	 */
	public ThirdCategory get(int third_category_id, Session s) throws Exception {
		return (ThirdCategory) super.get(ThirdCategory.class, third_category_id, s);
	}

	/**
	 * 根据名称获取三级类别
	 * 
	 * @param name
	 * @param s
	 * @return
	 */
	public ThirdCategory getByName(String name, Session s) throws Exception {
		Query query = s.createQuery("from ThirdCategory as tc where tc.third_category_name=:tcn ");
		query.setEntity("tcn", name);
		ThirdCategory tc = (ThirdCategory) query.uniqueResult();
		return tc;
	}

	/**
	 * 获取全部三级类别
	 * 
	 * @param s
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<ThirdCategory> getList(Session s) throws Exception {
		List<ThirdCategory> list = super.find("from ThirdCategory tc order by tc.sort asc", s);
		return list;
	}

	/**
	 * 根据二级ID获取三级子类别
	 * 
	 * @param s_id
	 * @param s
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<ThirdCategory> getListBySecondCategoryId(int s_id, Session s) {
		Query query = s.createQuery("from ThirdCategory as tc where tc.second_category_id=:tcid order by tc.sort asc");
		query.setInteger("tcid", s_id);
		return query.list();
	}
}
